import { UPDATEPAGENEWWORKEXP } from '../types/pagenewworkexp'
import { createAction } from 'redux-actions'
import { getUserArchiveInfoRequest } from '../../../../service/user-archive-controller'
import formatdata from '../../../../util/pagemethods/userArchInfo'

export const DOREQUESTNEWWORKEXP = createAction(UPDATEPAGENEWWORKEXP, payload => {
  return new Promise(resolve => {
    getUserArchiveInfoRequest({ ...payload }).then(({ data }) => {
      const { networkerror, entry, status, message } = data
      if (networkerror) {
        resolve({
          networkerror: true
        })
      } else {
        let Formatdata = new formatdata(entry || {}, '')
        let dataformat = Formatdata.getFormatData()
        resolve({
          networkerror: false,
          showEmpty: false,
          ...dataformat
        })
      }
    })
  })
})
